﻿using System.Collections.Generic;
using Weibo4Sharp.Model;
using Hammock.Web;

namespace Weibo4Sharp.Service
{
    public partial class WeiboService
    {
        public virtual WeiboStatus GetWeibo(long id)
        {
            return WithHammock<WeiboStatus>("statuses/show/{id}", FormatAsString, "?id=", id);
        }

        public virtual string GetWeiboUrl(long userId, long id)
        {
            return WithHammockLocation(string.Format("{0}/statuses/{1}?source=", userId, id, _consumerKey));
        }

        public virtual WeiboStatus SendWeibo(string status)
        {
            return WithHammock<WeiboStatus>(WebMethod.Post, "statuses/update", FormatAsString, "?status=", status);
        }

        public virtual WeiboStatus SendWeibo(string status, string annotations)
        {
            return WithHammock<WeiboStatus>(WebMethod.Post,
                "statuses/update", FormatAsString,
                "?status=", status,
                "&annotations=", annotations);
        }



        public virtual WeiboStatus SendWeibo(string status, double lat, double @long)
        {
            return WithHammock<WeiboStatus>(WebMethod.Post, "statuses/update", FormatAsString, "?status=", status, "&lat=", lat, "&long=", @long);
        }

        public virtual WeiboStatus SendWeibo(string status, double lat, double @long, string annotations)
        {
            return WithHammock<WeiboStatus>(WebMethod.Post, 
                "statuses/update", FormatAsString, 
                "?status=", status, 
                "&lat=", lat, 
                "&long=", @long,
                "&annotations=", annotations);
        }


        public virtual WeiboStatus SendWeibo(string status, long inReplyToStatusId)
        {
            return WithHammock<WeiboStatus>(WebMethod.Post, "statuses/update", FormatAsString, "?status=", status, "&in_reply_to_status_id=", inReplyToStatusId);
        }

        public virtual WeiboStatus SendWeibo(string status, long inReplyToStatusId, double lat, double @long)
        {
            return WithHammock<WeiboStatus>(WebMethod.Post, "statuses/update", FormatAsString, "?status=", status, "&in_reply_to_status_id=", inReplyToStatusId, "&lat=", lat, "&long=", @long);
        }

        public virtual WeiboStatus DeleteWeibo(long id)
        {
            return WithHammock<WeiboStatus>(WebMethod.Delete, "statuses/destroy/{id}", FormatAsString, "?id=", id);
        }

        /// <summary>
        /// Repost weibo
        /// </summary>
        /// <param name="id">weibo id to repost</param>
        /// <param name="status"></param>
        /// <param name="isComment">0=no comment|1=comment to current weibo|2=comment to original weibo|3=comment to both</param>
        /// <returns></returns>
        public virtual WeiboStatus Repost(long id, string status = "Repost", int isComment = 0)
        {
            return WithHammock<WeiboStatus>(WebMethod.Post, 
                "statuses/repost", FormatAsString,
                "?id=", id,
                "&status=", status,
                "&is_comment=", isComment);
        }

        //public virtual IEnumerable<WeiboStatus> Repost(long id)
        //{
        //    return WithHammock<IEnumerable<WeiboStatus>>("statuses/reWeibos/{id}", FormatAsString, "?id=", id);
        //}

        //public virtual IEnumerable<WeiboStatus> Repost(long id, int count)
        //{
        //    return WithHammock<IEnumerable<WeiboStatus>>("statuses/reWeibos/{id}", FormatAsString, "?id=", id, "&count=", count);
        //}

        public virtual IEnumerable<WeiboComment> ListComments(long id, int count = 20, int page = 1)
        {
            return WithHammock<IEnumerable<WeiboComment>>("statuses/comments", FormatAsString, "?id=", id, "&count=", count, "&page=", page);
        }

        /// <summary>
        /// Comment weibo
        /// </summary>
        /// <param name="id">weibo id to comment</param>
        /// <param name="comment">comment content</param>
        /// <param name="withoutMention">0=with reply@screenName|1=without</param>
        /// <param name="commentOri">comment on original weibo 0=no|1=yes</param>
        /// <returns></returns>
        public virtual WeiboComment Comment(long id, string comment, int withoutMention = 0, int commentOri = 0)
        {
            return WithHammock<WeiboComment>(WebMethod.Post,
                "statuses/comment", FormatAsString,
                "?id=", id,
                "&comment=", comment,
                "&without_mention=", withoutMention,
                "&comment_ori=", commentOri);
        }

        /// <summary>
        /// Comment weibo
        /// </summary>
        /// <param name="id">weibo id to comment</param>
        /// <param name="comment">comment content</param>
        /// <param name="cid">comment id to reply</param>
        /// <param name="withoutMention">0=with reply@screenName|1=without</param>
        /// <param name="commentOri">comment on original weibo 0=no|1=yes</param>
        /// <returns></returns>
        public virtual WeiboComment Comment(long id, string comment, long cid, int withoutMention = 0, int commentOri = 0)
        {
            return WithHammock<WeiboComment>(WebMethod.Post,
                "statuses/comment", FormatAsString,
                "?id=", id,
                "&comment=", comment,
                "&cid=", cid,
                "&without_mention=", withoutMention,
                "&comment_ori=", commentOri);
        }

        /// <summary>
        /// Reply a comment
        /// </summary>
        /// <param name="cid">comment id </param>
        /// <param name="comment">comment content</param>
        /// <param name="id">weibo id</param>
        /// <param name="withoutMention">0=with reply@screenName|1=without</param>
        /// <returns></returns>
        public virtual WeiboComment Reply(long cid, string comment, long id, int withoutMention = 0)
        {
            return WithHammock<WeiboComment>(WebMethod.Post,
                "statuses/reply", FormatAsString,
                "?cid=", cid,
                "&comment=", comment,
                "&id=", id,
                "&without_mention=", withoutMention);                
        }
        

        public virtual WeiboComment DeleteComment(long id)
        {
            return WithHammock<WeiboComment>(WebMethod.Delete,
                "statuses/comment_destroy/{id}", FormatAsString,
                "?id=", id);
        }

        public virtual IEnumerable<WeiboComment> DeleteComment(IEnumerable<object> ids)
        {
            return WithHammock<IEnumerable<WeiboComment>>(WebMethod.Delete,
                "statuses/comment/destroy_batch", FormatAsString,
                "?ids=", ids);
        }



        public virtual IEnumerable<WeiboUser> ListUsersWhoReWeiboed(long id)
        {
            return WithHammock<IEnumerable<WeiboUser>>("statuses/{id}/reWeiboed_by", FormatAsString, "?id=", id);
        }

        public virtual IEnumerable<WeiboUser> ListUsersWhoReWeiboed(long id, int count)
        {
            return WithHammock<IEnumerable<WeiboUser>>("statuses/{id}/reWeiboed_by", FormatAsString, "?id=", id, "&count=", count);
        }

        public virtual IEnumerable<int> ListUserIdsWhoReWeiboed(long id)
        {
            return WithHammock<IEnumerable<int>>("statuses/{id}/reWeiboed_by/ids", FormatAsString, "?id=", id);
        }

        public virtual IEnumerable<int> ListUserIdsWhoReWeiboed(long id, int count)
        {
            return WithHammock<IEnumerable<int>>("statuses/{id}/reWeiboed_by/ids", FormatAsString, "?id=", id, "&count=", count);
        }
    }
}
